home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
158_01
/
qe1
< prev
next >
Wrap
Text File
|
1987-10-10
|
8KB
|
366 lines
/* VERSION 0006 (DATE: 23/09/86) (TIME: 10:37) */
/*
e (qe) screen editor
(C) G. Nigel Gilbert, MICROLOGY, 1981
August-December 1981
Modified: To QE from e (ver 4.6a) by J.W. Haefner -- Oct 84-Mar 85
FILE: qe1
FUNCTIONS: dirmsk, expmsk,
printdirectory, envir, files, putonoff, getnumb, getlow
PURPOSE: environment; change files.
*/
#include "qe.h"
#define EXTENT 12
#define RECORDS 15
#define EXTSIZ 128
dirmsk()
{
char *pattp;
sint drv;
pattp = patt; /* use pattern find array to save extnl space */
if (scans(patt,FILELEN) == ESCKEY) return (YES);
drv = curdsk+1; /* drv = num for bdos file search */
if (!*pattp) pattp = "*.*";
else
if (patt[1] == ':') {
if ( ((drv = (toupper(*pattp) - '@')) < 1) || (drv > 16) )
drv = curdsk+1;
pattp += 2;
}
expmsk(drv,pattp);
}
expmsk(drv,str) /* create wildcard cp/m filename from str*/
sint drv;
char *str;
/* input: str: a user input string to expand to legal cp/m wildcard name
output: dirmsk: a string wh/ is a legal cp/m wildcard file name */
{ /* 10 */
sint stop,inmsk,inwild;
char c, wildarray[15], *wildname;
for (inwild=0;inwild<15;wildarray[inwild++]=' ');
wildname = wildarray; /* use pattern change array to save space */
wildname[0] = drv;
wildname[12] = '?';
wildname[14] = '\0';
stop = 8;
inmsk = 0; /* index for input mask */
inwild = 1; /* index for directory mask (output) */
while ((wildname[inwild]) && (str[inmsk])) {
switch (c=str[inmsk++]) { /*30*/
case '*' :
for( ; (inwild <= stop);inwild++)
wildname[inwild] = '?';
stop = 11;
break;
case '.' :
inwild = 9;
stop = 11;
break;
default:
wildname[inwild++] = toupper(c);
break;
} /*30*/
}
printdirectory(wildname);
} /*10*/
printdirectory(wildname)
char *wildname;
{
int y, *dsm, cols, loc, i, ndb, pos;
unsigned blsr, used, recs;
char c, a, entriesonline, *bsh, exm, al0;
char *parms;
sint dmabuf[128],drive;
putclr();
bdos(SETDMA,dmabuf);
drive = wildname[0]-1;
gotoxy(0,6);
puts("Directory of ");
putch(drive + 'A');
putch(':');
if (curdsk != (drive) && seldisk(drive) != FAIL) {
puts(" |(default drive is ");
putch(curdsk+'A');
puts(":|)");
}
used=0;
parms=bdos(DSKPARAMS);
bsh = parms+2;
exm = *(parms+4);
dsm = parms+5;
al0 = *(parms+9);
blsr = (1 << *bsh)/8; /*block size in kbytes*/
for(ndb=0;al0;al0 <<= 1, ndb++);
entriesonline=0;
begdim();
deleteline(2,(y=8));
pos=bdos(SEARCH1,wildname);
while (pos != 0xff) {
loc= pos << 5;
recs = (exm) ? EXTSIZ*(dmabuf[loc+EXTENT]%((exm)+1))
+ dmabuf[loc+RECORDS]
: dmabuf[loc+RECORDS];
used += (recs/(8*blsr))*blsr;
if (recs%(8*blsr)) used += blsr;
if (dmabuf[loc+EXTENT] <= exm) {
for (i=1, cols=0; i < 12; i++) {
c= dmabuf[loc+i] & 0x7f;
if (i == 9 && c != ' ') {
cols++;
putch('.');
}
if (c != ' ') {
cols++;
putch( (i >= 9 ? tolower(c) : c));
}
}
while (cols++ < 12) putch(' ');
if (++entriesonline == 5) {
deleteline(2,++y);
if (y == SHEIGHT) {
puts("[||<cr>| for MORE...]");
a = getkey();
begdim();
delpage((y=8));
gotoxy(2,8);
/* goto incomplete; */
}
entriesonline=0;
}
else puts(" : ");
}
pos=bdos(SEARCHN,wildname);
}
gotoxy(50,SHEIGHT);
for (i=1;((wildname[i]=='?') && (i<12)); i++);
if (i==12) {
puts("Free = ");
uspr((((*dsm+1)-ndb)*blsr)-used);
puts("k ");
}
puts("Files = ");
uspr(used);
putch('k');
if (curdsk != drive) seldisk(curdsk);
enddim();
gotoxy(0,0);
return;
}
envir()
{
char c;
struct addr anaddr;
puttext();
do {
putclr();
putstatusline(cline);
gotoxy(0,3);
puts("Edit context: |(|F| for file context) \n\n");
puts("A|uto indent ");
putonoff(autoin);
puts("B|ackup original file ");
putonoff(backup);
puts("T|ab stops every ");
uspr(tabwidth);
puts("\nS|trip trailing blanks ");
putonoff(!trail);
#if WWRAP
puts("R|ight margin ");
uspr(rtmarg);
puts("\n");
#endif
puts("L|ine:column display ");
putonoff(displaypos);
puts("H|orizontal scroll page ");
putonoff(blockscroll);
puts("E|xpert prompts ");
putonoff(expert);
puts("O|nscreen help ");
putonoff(helpon);
#if VRSNNUM
puts("V|ersion update ");
putonoff(version);
#endif
puts("\n|Memory allows for no more than ");
uspr( (slotsinmem-2)*PAGESIZE/sizeof(anaddr) );
puts("| lines of text");
puts("\n\n\nTo change, enter capital letter, or enter |Q| to return: ");
switch((c=getlow())) {
case 'a':
autoin= !autoin;
break;
case 'b':
backup= !backup;
break;
case 'l':
displaypos=!displaypos;
break;
case 'h':
blockscroll=!blockscroll;
break;
case 't':
puts("\n\n|Enter new |tab width|: ");
if (!(tabwidth=getnumb())) tabwidth=0;
break;
case 's':
trail=!trail;
break;
#if WWRAP
case 'r':
puts("\n\n|Enter new |right margin|: ");
if (!(rtmarg=getnumb())) rtmarg=LLIM;
if (rtmarg==LLIM) {
trail=NO;
autoin=YES;
}
else {
trail=YES;
autoin=NO;
}
break;
#endif
case 'f':
if(files()) goto escape;
break;
case 'e':
expert = !expert;
break;
case 'o':
helpon = !helpon;
break;
#if VRSNNUM
case 'v':
version = !version;
break;
#endif
case 'q':
case ESCKEY:
goto escape;
}
}
while (YES);
escape:
putclr();
topline=1;
if (helpon) dohelp();
putpage();
}
files()
{
char oldname[15], newname[15], c;
int dir, warn;
dir=curdsk;
do {
/* printdirectory(dir); */
putclr();
putstatusline(cline);
newcomm:
errmess=NULL;
gotoxy(0,1);
puts("|Enter |Q| to return to Edit context |D| to delete a file\n");
puts(" R| to rename a file |>| to view directory \n");
deleteline(0,3);
puts(" C| to change the name of the edited file ");
puts(filename);
deleteline(0,4);
deleteline(0,5);
gotoxy(6,4);
c=getlow();
putstatusline(cline);
switch (c) {
case ESCKEY:
return YES;
case 'q':
return NO;
case '>':
deleteline(6,4);
puts("Enter [drv:]mask| (RET for all) ");
dirmsk();
goto newcomm;
default:
if (c == 'r' || c == 'd' || c == 'c') {
deleteline(6,4);
puts("Name of file: ");
scans(oldname,15);
if (!oldname[0]) goto newcomm;
format(oldname);
}
switch (c) {
case 'd':
if (funlink(oldname) == FAIL) {
error("Can't delete");
goto newcomm;
}
break;
case 'r' :
deleteline(6,5);
puts("New name: ");
scans(newname,15);
format(newname);
if (!newname[0] || frename(oldname,newname) == FAIL) {
error("Can't rename");
goto newcomm;
}
break;
case 'c' :
strcpy(filename,oldname);
putstatusline(cline);
default:
goto newcomm;
}
}
}
while (YES);
}
putonoff(flag)
int flag;
{
puts(flag?"ON\n":"OFF\n");
}
getnumb()
{
int i, n;
char c, numb[5];
scans(numb,5);
n=qatoi(numb);
return n;
}
qatoi(nstr)
char *nstr;
{
int i,n;
char c;
n=0;
for (i=0; (c=nstr[i]); i++)
if (c >= '0' && c <= '9') n=n*10+c-'0';
return n;
}er